/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-05-06 23:09:53
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-09-24 17:48:23
 * @FilePath: /vue3-admin/src/router/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
    createRouter,
    createWebHashHistory,
    type RouteRecordRaw
} from 'vue-router';
import { systemRoutes } from './system';
import { templateRoutes } from './template';

export const Layout = () => import('@/layout/Layout.vue');

// 静态路由
export const constantRoutes: AppRouteRecordRaw[] = [
    // {
    //     path: '/redirect',
    //     component: Layout,
    //     meta: { hidden: true },
    //     children: [
    //         {
    //             path: '/redirect/:path(.*)',
    //             component: () => import('@/views/redirect/index.vue')
    //         }
    //     ]
    // },
    {
        path: '/login',
        name: 'LoginView',
        component: () => import('@/views/common/LoginView.vue'),
        meta: { hidden: true }
    },
    {
        path: '/401',
        name: 'NoPermission',
        component: () => import('@/views/common/401.vue'),
        meta: { hidden: true }
    },
    {
        path: '/iframe',
        name: 'Iframe',
        component: () => import('@/views/common/IframeView/IframeView.vue'),
        meta: { hidden: true }
    },
    ...templateRoutes,
    {
        path: '/:catchAll(.*)',
        name: 'NotFind',
        component: () => import('@/views/common/404.vue'),
        meta: { hidden: true }
    }
    // {
    //     path: '/',
    //     name: '/',
    //     component: Layout,
    //     redirect: '/dashboard',
    //     children: [
    //         {
    //             path: 'dashboard',
    //             component: () => import('@/views/dashboard/index.vue'),
    //             name: 'Dashboard', // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
    //             // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
    //             meta: {
    //                 title: 'dashboard',
    //                 icon: 'homepage',
    //                 affix: true,
    //                 keepAlive: true,
    //                 alwaysShow: false
    //             }
    //         },
    //         {
    //             path: '401',
    //             component: () => import('@/views/error-page/401.vue'),
    //             meta: { hidden: true }
    //         },
    //         {
    //             path: '404',
    //             component: () => import('@/views/error-page/404.vue'),
    //             meta: { hidden: true }
    //         }
    //     ]
    // },

    // {
    //     path: '/curd',
    //     component: Layout,
    //     meta: {
    //         alwaysShow: false
    //     },
    //     children: [
    //         {
    //             path: 'index',
    //             component: () => import('@/views/demo/curd/index.vue'),
    //             meta: {
    //                 title: '增删改查'
    //             }
    //         }
    //     ]
    // }

    // 外部链接
    // {
    //   path: "/external-link",
    //   component: Layout,
    //   children: [ {
    //       component: () => import("@/views/external-link/index.vue"),
    //       path: "https://www.cnblogs.com/haoxianrui/",
    //       meta: { title: "外部链接", icon: "link" },
    //     },
    //   ],
    // },
    // 多级嵌套路由
    /* {
         path: '/nested',
         component: Layout,
         redirect: '/nested/level1/level2',
         name: 'Nested',
         meta: {title: '多级菜单', icon: 'nested'},
         children: [
             {
                 path: 'level1',
                 component: () => import('@/views/nested/level1/index.vue'),
                 name: 'Level1',
                 meta: {title: '菜单一级'},
                 redirect: '/nested/level1/level2',
                 children: [
                     {
                         path: 'level2',
                         component: () => import('@/views/nested/level1/level2/index.vue'),
                         name: 'Level2',
                         meta: {title: '菜单二级'},
                         redirect: '/nested/level1/level2/level3',
                         children: [
                             {
                                 path: 'level3-1',
                                 component: () => import('@/views/nested/level1/level2/level3/index1.vue'),
                                 name: 'Level3-1',
                                 meta: {title: '菜单三级-1'}
                             },
                             {
                                 path: 'level3-2',
                                 component: () => import('@/views/nested/level1/level2/level3/index2.vue'),
                                 name: 'Level3-2',
                                 meta: {title: '菜单三级-2'}
                             }
                         ]
                     }
                 ]
             },
         ]
     }*/
];

export const authRoutes: AppRouteRecordRaw[] = [
    {
        path: '/',
        name: 'Root',
        component: Layout,
        redirect: '/dashboard',
        meta: { icon: 'system' },
        children: [
            {
                path: '/dashboard',
                name: 'DashboardView',
                component: () =>
                    import('@/views/common/DashboardView/DashboardView.vue'),
                meta: {
                    title: '首页',
                    icon: 'homepage',
                    affix: true,
                    keepAlive: true
                }
            }
        ]
    },

    ...systemRoutes
];

/**
 * 创建路由
 */
const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes as RouteRecordRaw[],
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 })
});

/**
 * 重置路由
 */
export function resetRouter() {
    router.getRoutes().forEach((route) => {
        const { name } = route;
        if (name) {
            router.removeRoute(name);
        }
    });
}

export default router;
